<script setup lang="ts">
import { useK8SApi } from "@/views/domain/kubeHud/api/k8s/k8s";
import { Pod } from "@/views/domain/kubeHud/api/k8s/types";
import { onMounted, reactive, ref } from "vue";
import NamespaceSelector from "../namespace/widgets/NamespaceSelector.vue";
import RouterLinkBtn from "@/views/widgets/RouterLinkBtn/index.vue";
import KPodList from "./widgets/KPodList.vue";
const { podRepo } = useK8SApi();

const podList = ref<Pod[]>();
const loading = ref(false);
const query = reactive<{
  namespace?: string;
}>({ namespace: "default" });

const reloadPodList = async () => {
  loading.value = true;

  const { data, ok } = await podRepo.getPodList({
    namespace: query.namespace
  });

  if (ok) {
    podList.value = data.items;
  }

  loading.value = false;
};

onMounted(() => {
  reloadPodList();
});
</script>

<template>
  <div>
    <el-card>
      <el-form v-model="query" inline label-position="top">
        <el-form-item label="Namespace" prop="namespace">
          <NamespaceSelector
            v-model="query.namespace"
            @change="reloadPodList"
          />
        </el-form-item>
      </el-form>
      <KPodList :namespace="query.namespace" />
    </el-card>
  </div>
</template>
<style lang="scss" scoped></style>
